package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Review;
import cn.wolfcode.trip.base.mapper.ReviewMapper;
import cn.wolfcode.trip.base.service.IReviewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ReviewServiceImpl implements IReviewService {
    @Autowired
    private ReviewMapper reviewMapper;
    @Override
    public Integer selectUnRead(Long id) {
        return reviewMapper.selectUnRead(id);
    }

    @Override
    public List<Review> selectReviewByUserId(Long id, String types) {
        return reviewMapper.selectReviewByUserId(id);
    }

    @Override
    public void changeState(Long travelId) {
        reviewMapper.changeState(travelId);

    }
    @Override
    public void save(String content, Long userId, Long travelId) {
       if(content !=null && content.trim().length()!=0){

           Review review = new Review();
          review.setUserId(userId);
          review.setTravelId(travelId);
          review.setCreatetime(new Date());
          review.setContent(content);
          review.setState(false);
          reviewMapper.insert(review);
       }
    }

    @Override
    public List<Review> selectContenByTravelId(Long travelId) {
        List<Review> reviews= reviewMapper.selectContenByTravelId(travelId);

        return reviews;
    }
}
